﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



using System.Drawing;
using System.Data.SqlClient;
using System.Data;
public partial class Read : System.Web.UI.Page
{
    public string lblContent = "";
    public string lblUserHome = "";
    public string trbMsg = "alert('글쓴이만 보낼 수 있습니다.')";
    public string TagDisplay = "display:none";

    public string ServerURL = "localhost:63451";

    protected void Page_Load(object sender, EventArgs e)
    {
       

        if (!IsPostBack)
        {

            //카테고리 초기화
            //1. DB INSERT Setting
            SqlConnection sqlConn = new SqlConnection();
            sqlConn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;

            SqlDataAdapter sqldap = new SqlDataAdapter(); 
            sqldap.SelectCommand = new SqlCommand();
            sqldap.SelectCommand.Connection = sqlConn;

            DataSet ds = new DataSet();

            sqldap.SelectCommand.CommandText = "SELECT * FROM UCCLIGHT WHERE UCCIDX="+Request.QueryString["UCCIDX"];
            sqldap.Fill(ds);
            //글 불러 오기
            lblBoardTitle.Text = ds.Tables[0].Rows[0]["UCCTitle"].ToString();
            lblContent = ds.Tables[0].Rows[0]["UCCContent"].ToString();
            lblUserNickName.Text = ds.Tables[0].Rows[0]["UCCUserName"].ToString();
            lblDate.Text = ds.Tables[0].Rows[0]["UCCWriteDate"].ToString();
            hdnFileName.Value = ds.Tables[0].Rows[0]["UCCFile"].ToString(); 

            int opt = 0;
            opt = int.Parse(ds.Tables[0].Rows[0]["UCCEncodingOption"].ToString());

            switch(opt)
            {
                case 0:
                    lblEncodingOpt.Text =  "저화질";
                     break;
                case 1:
                    lblEncodingOpt.Text =  "중화질";
                     break;
                case 2:
                    lblEncodingOpt.Text =  "고화질";
                     break;
                case 3:
                    lblEncodingOpt.Text =  "Smooth Streaming";
                     break;
                default:
                     lblEncodingOpt.Text = "저화질";
                     break;
            }

           // btnThumInsert.Attributes.Add("onclick", "return validate();");
        }
    }

    public void Status_Check()
    {
        //인코딩 값 체크하여 화면에 보여주기
        Response.Write("<script>alert('아직 인코딩 중입니다.');");  
    }

    public void Status_Thumbnail_Update()
    {
        hdnStatus.Value = "1"; // 인코딩 값 받아 오기
        hdnThumbList.Value.Split('/'); // 인코딩 값 받아 오기

        //1. DB INSERT Setting
        SqlConnection sqlConn = new SqlConnection();
        sqlConn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;

        SqlCommand sqlCmd = new SqlCommand();
        sqlCmd.Connection = sqlConn;

        SqlParameter[] sqlPrm;

        sqlPrm = new SqlParameter[3];
        sqlPrm[0] = new SqlParameter("@UCCStatus", hdnStatus.Value);
        sqlPrm[1] = new SqlParameter("@UCCImage", hdnThumb.Value);
        sqlPrm[2] = new SqlParameter("@UCCThumbnail", hdnThumbList.Value.Replace(String.Format("http://{0}", ServerURL), String.Empty));


        string Query = @"update [UCCLight] set UCCStatus=@UCCStatus, UCCImage=@UCCImage, UCCThumbnail=@UCCThumbnail";

        foreach (SqlParameter param in sqlPrm)
        {
            sqlCmd.Parameters.Add(param);
        }
        sqlCmd.CommandText = Query;
        sqlConn.Open();
        sqlCmd.ExecuteNonQuery();
        sqlConn.Close();

        Response.Write("<script>alert('썸네일 이미지가 저장되었습니다.');");        

    }


    protected void btnThumInsert_Click(object sender, EventArgs e)
    {




    }
}
